package com.woniuxy.service.impl;

import com.woniuxy.Exception.serviceException;
import com.woniuxy.dao.AbsenceDao;
import com.woniuxy.entity.Absence;
import com.woniuxy.entity.PageBean;
import com.woniuxy.service.AbsenceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.exceptions.PersistenceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class AbsenceServiceImpl implements AbsenceService {
   @Resource
    AbsenceDao absenceDao;
    @Override
    public void addAbsence(Absence absence) {
     absenceDao.insertAbsence(absence);
     log.info("添加成功");
    }

    @Override
    public void upAbsence(Absence absence) {
absenceDao.updateAbsence(absence);
      log.info("修改成功");

    }

    @Override
    public PageBean<Absence> getAllAbsence(Absence absence, int pageIndex, int pageSize) {
  try {
      PageBean<Absence>pageBean=new PageBean<>();
pageBean.setPageIndex(pageIndex);
pageBean.setPageSize(pageSize);
  int pageCount=absenceDao.selectAbsenceCount(absence);
  pageBean.setTotalRecord(pageCount);
     pageBean.setBeanList(absenceDao.selectAllAbsence(absence, pageIndex, pageSize));

      return pageBean;
  }catch(PersistenceException e){


      throw new serviceException("系统维护中");
  }







    }


}
